package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-07-21
 * Time: 16:30
 */
class MyThread extends Thread {
    /**
     * 相当于线程的入口方法, 描述线程跑起来后要做什么
     */
    @Override
    public void run() {
        while (true){
            System.out.println("hello world");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

public class Demo1 {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();//创建线程, 这个操作就会再次曾调用操作系统提供的"创建线程"
        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
